package com.zry.fertilizer.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.zry.fertilizer.R
import com.zry.fertilizer.been.SpinnerBean


class SpinnerAdapterKt(private val spinnerInfoList: MutableList<SpinnerBean>, private val context: Context) : BaseAdapter() {

    override fun getItem(position: Int): Any {
        return spinnerInfoList[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return spinnerInfoList.size
    }


    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        val layoutInflater = LayoutInflater.from(context)// //创建视图容器工厂并设置上下文
        val listView: ListItemView?
        var convertView: View? = null
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.spinner_item, null) // 创建list_item.xml布局文件的视图
            listView = ListItemView()
            listView.spinnerName = convertView?.findViewById(R.id.spinnerName)
            convertView?.tag = listView
        } else {
            listView = convertView.tag as ListItemView
        }
        listView.spinnerName?.text = spinnerInfoList[position].dataName
        return convertView
    }

    inner class ListItemView {
        //缓存的价值
        var spinnerName: TextView? = null
    }

}
